package com.thb.pay.payment.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.thb.pay.api.payment.AgentpayPassageAccountServiceApi;
import com.thb.pay.api.payment.vo.req.AgentpayPassageAccountPageReq;
import com.thb.pay.api.payment.vo.req.AgentpayPassageAccountReq;
import com.thb.pay.api.payment.vo.resp.AgentpayPassageAccountVo;
import com.thb.pay.core.utils.PageResult;
import com.thb.pay.db.entity.SuperEntity;
import com.thb.pay.payment.entity.AgentpayPassageAccount;
import com.thb.pay.payment.service.AgentpayPassageAccountService;
import com.xiaoleilu.hutool.collection.CollUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 代付-通道-账户表 前端控制器
 * </p>
 *
 * @author lucky
 * @since 2019-07-21
 */
@Slf4j
@RestController
public class AgentpayPassageAccountController implements AgentpayPassageAccountServiceApi {

    @Autowired
    private AgentpayPassageAccountService agentpayPassageAccountService;

    @Override
    public PageResult<AgentpayPassageAccountVo> findPage(@RequestBody AgentpayPassageAccountPageReq pageReq) {
        return agentpayPassageAccountService.findPage(pageReq);
    }

    @Override
    public List<AgentpayPassageAccountVo> findAllList() {
        return agentpayPassageAccountService.findAllList(null);
    }

    @Override
    public AgentpayPassageAccountVo getById(@RequestParam("id") Long id) {
        return agentpayPassageAccountService.getById(id);
    }

    @Override
    public void add(@RequestBody AgentpayPassageAccountReq agentpayPassageAccountReq) {
        agentpayPassageAccountService.add(agentpayPassageAccountReq);
    }

    @Override
    public void update(@RequestBody AgentpayPassageAccountReq agentpayPassageAccountReq) {
        agentpayPassageAccountService.update(agentpayPassageAccountReq);
    }

    @Override
    public void deleteBatchIds(@RequestBody List<Long> ids) {
        LambdaQueryWrapper<AgentpayPassageAccount> wrapper = new LambdaQueryWrapper();
        wrapper.in(AgentpayPassageAccount::getId, ids);
        List<AgentpayPassageAccount> targetDbResultList = agentpayPassageAccountService.selectList(wrapper);
        if (CollUtil.isNotEmpty(targetDbResultList)) {
            targetDbResultList.forEach(payType -> {
                payType.setDelFlag(SuperEntity.DEFAULT_DELETE_FLAG);
            });
            agentpayPassageAccountService.updateBatchById(targetDbResultList);
        }
    }
}
